using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Grpc.Net.Client;
using GrpcServer;

namespace GrpcClient;

[ObservableObject]
public partial class MainPageViewModel {
    [ObservableProperty] private string _input;

    [ObservableProperty] private string _output;

    private EchoService.EchoServiceClient _client;

    [RelayCommand]
    private async Task ConnectAsync() {
        var channel = GrpcChannel.ForAddress("http://localhost:5026");
        _client = new EchoService.EchoServiceClient(channel);
    }

    [RelayCommand]
    private async Task SendAsync() {
        var response =
            await _client.EchoAsync(new EchoMessage { Message = Input });
        Output = response.Message;
    }
}